<template>
  <div>
    <!-- 三级联动全局组件 -->
    <!-- 不需要再用import引入三级联动了，因为已经是全局组件了，可以直接使用 -->
    <TypeNav />
    <ListContainer />
    <TodayRecommend />
    <Rank />
    <Like />
    <Floor v-for="(floor,index) in floorList" :key="floor.id" :list="floor"/>
    <Brand />
  </div>
</template>

<script>
//引入其余的组件
import ListContainer from "@/pages/Home/ListContainer";
import TodayRecommend from "@/pages/Home/TodayRecommend";
import Rank from "@/pages/Home/Rank";
import Like from "@/pages/Home/Like";
import Floor from "@/pages/Home/Floor";
import Brand from "@/pages/Home/Brand";
import { mapState } from 'vuex';

export default {
  name: "Home",
  mounted() {
    //派发action：通过Vuex发起ajax请求，将数据存储在仓库中
    this.$store.dispatch("getFloorList");
    this.$store.dispatch("getUserInfo");
  },
  components: {
    ListContainer,
    TodayRecommend,
    Rank,
    Like,
    Floor,
    Brand,
  },
  computed: {
    ...mapState({
      floorList:state=>state.home.floorList// 得到的是store文件下home中的state.floorList
    })
  }
};
</script>